<template>
  <div class="wapper">
    <div class="header">
      <p>热门帖子</p>
      <img src="https://gw.alicdn.com/tfs/TB1todsX79E3KVjSZFGXXc19XXa-33-18.png" alt>
    </div>
    <div class="message-list">
      <div class="img-list" v-for="(item, index) in dataList" :key="index" @click="openLink(item)">
        <div class="image">
          <img :src="item.file_path" width="100%" alt>
        </div>
        <div class="content-box">
          <p class="content-header one-txt-cut">{{ item.title }}</p>
          <div class="img-box">
            <div class="num-box">
              <img src="https://gw.alicdn.com/tfs/TB1fsxZX21H3KVjSZFBXXbSMXXa-18-16.png" alt>
              <p class="text">{{item.like_nums || 0}}</p>
            </div>
            <div class="num-box">
              <img src="https://gw.alicdn.com/tfs/TB1OAX1X8WD3KVjSZFsXXcqkpXa-21-17.png" alt>
              <p class="text">{{item.comment_nums || 0}}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getListPortalTops } from "@/api/home";

export default {
  name: "OtherItem",
  data() {
    return {
      listQuery: {
        current: 1,
        limit: 8,
        company_id: localStorage.getItem("companyId") - 0
      },
      dataList: []
    };
  },
  methods: {
    openLink(item) {
      if (item.type == "draw") {
        this.$router.push({ path: "/Trunplate1", query: { drawId: item.id } });
      }
      if (item.type == "active") {
        this.$router.push({
          path: "/ActivityDetail",
          query: { id: item.id, status: item.active_status, name: "home" }
        });
      }
      if (item.type == "article") {
        this.$router.push({
          path: "/CommunityDetail",
          query: { id: item.id, name: "article" }
        });
      }
      if (item.type == "proposal") {
        this.$router.push({
          path: "/proposalDetail",
          query: { id: item.id, name: "proposal" }
        });
      }
      if (item.vote_type == 1) {
        this.$router.push({ path: "/VoteTypeTwo", query: { id: item.id } });
      }
      if (item.vote_type == 2) {
        this.$router.push({ path: "/VoteTypeThree", query: { id: item.id } });
      }
      if (item.type == "questionnaire") {
        this.$router.push({ path: "/SurveyDetails", query: { id: item.id } });
      }
    },
    async initList() {
      let query = Object.assign({}, this.listQuery);
      let res = await getListPortalTops(query);
      let result = res.data;
      if (result.status == 100) {
        this.dataList = result.data.rows;
      }
    }
  },
  created() {
    setTimeout(() => {
      this.initList();
    }, 1000);
  }
};
</script>

<style lang="scss" scoped>
.wapper {
  background: rgb(243, 248, 252);
  padding-bottom: 40px;
  .header {
    background-color: #fff;
    padding: 7px;
    display: flex;
    align-items: flex-start;
    font-size: 18px;
    line-height: 18px;
    img {
      width: 22px;
      height: 12px;
      margin-left: 6px;
    }
  }
  .message-list {
    margin: 10px 7px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .img-list {
      width: 175px;
      margin-bottom: 10px;
      background-color: #fff;
      border-radius: 5px;
      overflow: hidden;
      .image {
        width: 175px;
        height: 82px;
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        overflow: hidden;
      }
      .content-box {
        width: 172px;
        padding: 10px 7px 7px;
        .content-header {
          font-size: 14px;
          line-height: 20px;
        }
        .img-box {
          display: flex;
          align-items: center;
          color: #ccc;
        }
        .num-box {
          margin-right: 12px;
          margin-top: 10px;
          display: flex;
          align-items: center;
          img{
            width: 12px;
          }
          .text {
            padding-left: 5px;
          }
        }
      }
    }
  }
}
</style>
